﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SMTC.BO.UserPower;
using System.Data;
using SMTC.WebCommon.Common;

public partial class Common_SelectReceiver : BasePage
{
    private NewsReceiverGridviewBind newsreceiver = new NewsReceiverGridviewBind();
    private SearchReceiver search = new SearchReceiver();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SelectReceiverBind();

        }
    }

    private void SelectReceiverBind()
    {
        DataSet set = newsreceiver.SELECT_News_Receiver_GridViewBind();
        GridViewReceiverSelect.DataSource = set.Tables[0].DefaultView;
        GridViewReceiverSelect.DataBind();

    }
    protected void ButtonGO_Click(object sender, EventArgs e)
    {

        for (int i = 0; i < GridViewReceiverSelect.Rows.Count; i++)
        {

            CheckBox check = (CheckBox)(GridViewReceiverSelect.Rows[i].FindControl("checkuser"));
            if (check.Checked == true)
            {
                HiddenTOReceiver.Value += GridViewReceiverSelect.Rows[i].Cells[1].Text + ";";
            }


        }
        if (HiddenTOReceiver.Value == "")
            ClientScript.RegisterStartupScript(Page.GetType(), "", "NoReceiver()", true);
        else
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "", "getReceiver()", true);
        }

    }
    protected void CheckALL_CheckedChanged(object sender, EventArgs e)
    {
        if (CheckALL.Checked)
        {
            for (int i = 0; i < GridViewReceiverSelect.Rows.Count; i++)
            {
                CheckBox check = (CheckBox)(GridViewReceiverSelect.Rows[i].FindControl("checkuser"));
                check.Checked = true;
            }
        }
        else
        {
            for (int i = 0; i < GridViewReceiverSelect.Rows.Count; i++)
            {
                CheckBox check = (CheckBox)(GridViewReceiverSelect.Rows[i].FindControl("checkuser"));
                check.Checked = false;
            }

        }
    }
    protected void GridViewReceiverSelect_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    }
    protected void ButtonSearch_Click(object sender, EventArgs e)
    {
        GridViewReceiverSelect.DataSource = search.Search_Receiver(TextBoxUser.Text);
        GridViewReceiverSelect.DataBind();
    }
    protected void GridViewReceiverSelect_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        if (e.NewPageIndex >= 0 && e.NewPageIndex < GridViewReceiverSelect.PageCount)
        {
            GridViewReceiverSelect.PageIndex = e.NewPageIndex;
            SelectReceiverBind();
        }
    }
    protected void ButtonALL_Click(object sender, EventArgs e)
    {

        Response.Redirect("SelectReceiver.aspx");
    }
}